<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>账单记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <script src="/layuiadmin/layui/layui.js"></script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">开始</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" id="beginTime" name="beginTime" placeholder="yyyy-MM-dd">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">结束</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" id="endTime" name="endTime" placeholder="yyyy-MM-dd">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card">
            <div class="layui-card-body">
                <div style="padding-bottom: 10px;">
                    <button class="layui-btn layuiadmin-btn-admin" data-type="add">添加</button>
                </div>
                <table id="myTable" lay-filter="myTable"></table>
            </div>
        </div>
    </div>

    <script>

        timestampToDate = function(timestamp) {
            let unixtimestamp = new Date(timestamp*1000);
            let year = 1900 + unixtimestamp.getYear();
            let month = "0" + (unixtimestamp.getMonth() + 1);
            let date = "0" + unixtimestamp.getDate();
            let hour = "0" + unixtimestamp.getHours();
            let minute = "0" + unixtimestamp.getMinutes();
            let second = "0" + unixtimestamp.getSeconds();
            return year + "-" + month.substring(month.length-2, month.length)  + "-" + date.substring(date.length-2, date.length)
                + " " + hour.substring(hour.length-2, hour.length) + ":"
                + minute.substring(minute.length-2, minute.length) + ":"
                + second.substring(second.length-2, second.length);
        }

        layui.config({
            base: '/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index','table'], function(){
            let $ = layui.$
                ,form = layui.form
                ,table = layui.table
                ,layDate = layui.laydate;

            layDate.render({
                elem: '#beginTime'
            });
            layDate.render({
                elem: '#endTime'
            });

            //用户管理
            table.render({
                elem: '#myTable'
                ,url: 'getList'
                ,cols: [[
                    {field: 'changeAmountStr', title: '变动(元)'}
                    ,{field: 'amountStr', title: '余额(元)'}
                    ,{field: 'des', title: '原因'}
                    ,{field: 'createTime', title: '创建时间', templet: '<div>{{ timestampToDate(d.createTime) }}</div>'}
                ]]
                ,page: true
                ,height: 'full-230'
                ,text: {none: '无数据'}
            });

            //监听搜索
            form.on('submit(search)', function(data){
                let field = data.field;

                //执行重载
                table.reload('myTable', {
                    where: field
                });
            });

            //事件
            let active = {
                add: function(){
                    layer.open({
                        type: 2
                        ,title: '添加'
                        ,content: 'showAdd'
                        ,area: ['620px', '400px']
                    });
                }
            }
            $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
                let type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
</body>
</html>

